package com.ang.juc.n4.t1;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * 使用park、unpark
 *
 * unpark(t1)先执行后，再去t1中调用park，不会停止t1线程的运行，需要再次调用park
 */
@Slf4j
public class Test3 {
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            LockSupport.park();
            log.info("t1线程运行");
        });

        Thread t2 = new Thread(() -> {
            log.info("t2线程运行");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //2s后唤醒t1
            LockSupport.unpark(t1);
        });

        t1.start();
        t2.start();
    }
}
